home *** CD-ROM | disk | FTP | other *** search
- head 2.4;
- access;
- symbols
- C_2:2.4
- C_1:1.5;
- locks; strict;
- comment @ * @;
-
-
- 2.4
- date 93.12.01.00.25.17; author Aussem; state Exp;
- branches;
- next 2.3;
-
- 2.3
- date 93.11.28.21.03.14; author Aussem; state Exp;
- branches;
- next 2.2;
-
- 2.2
- date 93.11.28.16.01.05; author Aussem; state Exp;
- branches;
- next 2.1;
-
- 2.1
- date 93.11.23.19.58.39; author Aussem; state Exp;
- branches;
- next 1.7;
-
- 1.7
- date 93.11.20.23.50.31; author Aussem; state Exp;
- branches;
- next 1.6;
-
- 1.6
- date 93.11.20.21.32.39; author Aussem; state Exp;
- branches;
- next 1.5;
-
- 1.5
- date 93.11.06.15.59.47; author Aussem; state Exp;
- branches;
- next 1.4;
-
- 1.4
- date 93.10.18.23.50.32; author Aussem; state Exp;
- branches;
- next 1.3;
-
- 1.3
- date 93.09.18.16.47.47; author Aussem; state Exp;
- branches;
- next 1.2;
-
- 1.2
- date 93.09.10.01.51.50; author Aussem; state Exp;
- branches;
- next 1.1;
-
- 1.1
- date 93.09.08.16.27.13; author Aussem; state Exp;
- branches;
- next ;
-
-
- desc
- @misc routines
- @
-
-
- 2.4
- log
- @timeozone now works correctly
- @
- text
- @/*
- * Miscellaneous support functions for smail/rmail
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Log: misc.c,v $
- * Revision 2.3 1993/11/28 21:03:14 Aussem
- * only in rmail mode the delivering time will be logged
- *
- * Revision 2.2 1993/11/28 16:01:05 Aussem
- * get_time() insert
- * maillog() will now logs the duration of delivering the mail
- *
- * Revision 2.1 1993/11/23 19:58:39 Aussem
- * Version 2.0 check in
- *
- * Revision 1.7 1993/11/20 23:50:31 Aussem
- * no ok, .. output if we are rmail
- *
- * Revision 1.6 1993/11/20 21:32:39 Aussem
- * extended Debug options
- *
- * Revision 1.5 1993/11/06 15:59:47 Aussem
- * maillog() now works better
- *
- * Revision 1.4 1993/10/18 23:50:32 Aussem
- * enforcer hit in record() removed
- *
- * Revision 1.3 1993/09/18 16:47:47 Aussem
- * insert GNU license text in the header
- *
- * Revision 1.2 1993/09/10 01:51:50 Aussem
- * new support for wCNews styled logfile with maillog()
- *
- * Revision 1.1 1993/09/08 16:27:13 Aussem
- * Initial revision
- *
- *
- */
-
- static char *rcsid="$Id: misc.c,v 2.3 1993/11/28 21:03:14 Aussem Exp Aussem $";
-
- # include <stdio.h>
- # include <stdlib.h>
- # include <sys/types.h>
- # include <ctype.h>
- # include "defs.h"
- # include <time.h>
-
- extern int exitstat; /* set if a forked mailer fails */
- extern enum edebug debug; /* how verbose we are */
- extern enum ehandle handle; /* what we handle */
- extern char *uuxargs; /* arguments given to uux */
- extern int queuecost; /* threshold for queueing mail */
- extern int maxnoqueue; /* max number of uucico's */
- extern enum erouting routing; /* when to route addresses */
- extern char hostdomain[]; /* */
- extern char hostname[]; /* */
- extern char hostuucp[]; /* */
- extern char *pathfile; /* location of path database */
- extern char *spoolfile; /* file name of spooled message */
- extern FILE *spoolfp; /* file ptr to spooled message */
- extern int spoolmaster; /* set if creator of spoolfile */
- extern char logfile[];
- extern char sentfile[];
- extern char dateline[];
-
- char smarthost[SMLBUF];
-
- struct tm *gmt, *loc; /* GMT and local time structure */
- time_t now; /* current system time */
- char nows[50]; /* time in ctime format */
- char arpanows[50]; /* time in arpa format */
-
- # ifdef MAILLOG
- extern char maillogfile[];
- extern int asrmail;
-
- void
- maillog(to_user,to_host, from, size,okay)
- char *to_user,*to_host;
- char *from;
- long size;
- char okay;
- {
- static FILE *fp=NULL;
- char *logtime, buf[SMLBUF];
-
- logtime = strcpy(buf, nows);
- logtime[19] = '\0';
- logtime += 4;
-
- if(debug==NO && !asrmail)
- {
- /* sorry CONSOLE: does not work :-( so I use * */
- FILE *fp=fopen("*","w+");
- if(to_host[0]!='\0')
- fprintf(fp,"%s, mail sent from %s to %s via %s\n",okay?"Ok":"Error",from,to_user,to_host);
- else
- fprintf(fp,"%s, mail sent from %s to %s\n",okay?"Ok":"Error",from,to_user);
- fclose(fp);
- }
-
- fp=fopen(maillogfile,"a");
- if(fp)
- {
- if(asrmail)
- {
- if(to_host[0]!='\0')
- fprintf(fp,"%s: %c '%s' '%s!%s' %ld bytes %d days\n",logtime,okay,from,to_host,to_user,size,get_time(dateline));
- else
- fprintf(fp,"%s: %c '%s' '%s' %ld bytes %d days\n",logtime,okay,from,to_user,size,get_time(dateline));
- fclose(fp);
- }
- else
- {
- if(to_host[0]!='\0')
- fprintf(fp,"%s: %c '%s' '%s!%s' %ld bytes\n",logtime,okay,from,to_host,to_user,size);
- else
- fprintf(fp,"%s: %c '%s' '%s' %ld bytes\n",logtime,okay,from,to_user,size);
- fclose(fp);
- }
- }
- }
- # endif
-
- # ifdef RECORD
- FILE *
- record(command, from, size)
- char *command, *from;
- long size;
- {
- FILE *fd;
- char *logtime, buf[SMLBUF];
-
- logtime = strcpy(buf, nows);
- logtime[19] = '\0';
- logtime += 4;
-
- fd = fopen(sentfile, "a");
- if(!fd)
- return(NULL);
- (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n",
- logtime, command, from, size);
- while(fgets(buf, sizeof(buf), spoolfp) != NULL) {
- (void) fputs(buf, fd);
- }
- (void) fclose(fd);
- return(NULL);
- }
- # endif
-
-
- setdates()
- {
- (void) time(&now);
- (void) strcpy(nows, ctime(&now));
- gmt = gmtime(&now);
- loc = localtime(&now);
- (void) strcpy(arpanows, arpadate(nows));
- }
-
- /*
- ** Note: This routine was taken from sendmail
- **
- ** ARPADATE -- Create date in ARPANET format
- **
- ** Parameters:
- ** ud -- unix style date string. if NULL, one is created.
- **
- ** Returns:
- ** pointer to an ARPANET date field
- **
- ** Side Effects:
- ** none
- **
- ** WARNING:
- ** date is stored in a local buffer -- subsequent
- ** calls will overwrite.
- **
- ** Bugs:
- ** Timezone is computed from local time, rather than
- ** from whereever (and whenever) the message was sent.
- ** To do better is very hard.
- **
- ** Some sites are now inserting the timezone into the
- ** local date. This routine should figure out what
- ** the format is and work appropriately.
- */
-
- #ifdef AMIGA
- extern char *_TZ;
-
- static short int DaysofMonth[]=
- { 31, 28, 31, 30,
- 31, 30, 31, 31,
- 30, 31, 30, 31 };
-
-
- static char *Weekday[]=
- {
- "Sun",
- "Mon",
- "Tue",
- "Wed",
- "Thu",
- "Fri",
- "Sat"
- };
-
- static char *Month[]=
- {
- "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
- };
-
-
- char *
- arpadate(ud)
- register char *ud;
- {
- struct tm *Time;
- time_t t;
- static char timestr[40]="";
- char *timezone;
- char *getenv();
-
- _TZ=timezone=strdup(getenv("TZ"));
- __tzset();
-
- time(&t);
- Time=localtime(&t);
- if(Time)
- sprintf(timestr, "%s, %02d %s %04d %02d:%02d:%02d %s",
- Weekday[Time->tm_wday],
- Time->tm_mday,
- Month[Time->tm_mon],
- Time->tm_year+1900,
- Time->tm_hour,
- Time->tm_min,
- Time->tm_sec,
- __tzdtn?__tzdtn:(__tzstn?__tzstn:"GMT"));
- return timestr;
- }
- #else
- char *
- arpadate(ud)
- register char *ud;
- {
- register char *p;
- register char *q;
- static char b[40];
- extern char *ctime();
- register int i;
- #ifndef BSD
- extern char *tzname[];
- time_t t, time();
- #else
- /* V7 and 4BSD */
- struct timeb t;
- extern struct timeb *ftime();
- extern char *timezone();
- #endif
-
- /*
- ** Get current time.
- ** This will be used if a null argument is passed and
- ** to resolve the timezone.
- */
-
- #ifndef BSD
- (void) time(&t);
- if (ud == NULL)
- ud = ctime(&t);
- #else
- /* V7 or 4BSD */
- ftime(&t);
- if (ud == NULL)
- ud = ctime(&t.time);
- #endif
-
- /*
- ** Crack the UNIX date line in a singularly unoriginal way.
- */
-
- q = b;
-
- p = &ud[8]; /* 16 */
- if (*p == ' ')
- p++;
- else
- *q++ = *p++;
- *q++ = *p++;
- *q++ = ' ';
-
- p = &ud[4]; /* Sep */
- *q++ = *p++;
- *q++ = *p++;
- *q++ = *p++;
- *q++ = ' ';
-
- p = &ud[22]; /* 1979 */
- *q++ = *p++;
- *q++ = *p++;
- *q++ = ' ';
-
- p = &ud[11]; /* 01:03:52 */
- for (i = 8; i > 0; i--)
- *q++ = *p++;
-
- /* -PST or -PDT */
- #ifndef BSD
- p = tzname[localtime(&t)->tm_isdst];
- #else
- p = timezone(t.timezone, localtime(&t.time)->tm_isdst);
- #endif
- if (p[3] != '\0')
- {
- /* hours from GMT */
- p += 3;
- *q++ = *p++;
- if (p[1] == ':')
- *q++ = '0';
- else
- *q++ = *p++;
- *q++ = *p++;
- p++; /* skip ``:'' */
- *q++ = *p++;
- *q++ = *p++;
- }
- else
- {
- *q++ = ' ';
- *q++ = *p++;
- *q++ = *p++;
- *q++ = *p++;
- }
-
- p = &ud[0]; /* Mon */
- *q++ = ' ';
- *q++ = '(';
- *q++ = *p++;
- *q++ = *p++;
- *q++ = *p++;
- *q++ = ')';
-
- *q = '\0';
- return (b);
- }
- #endif
-
- /*
- * The user name "postmaster" must be accepted regardless of what
- * combination of upper and lower case is used. This function is
- * used to convert all case variants of "postmaster" to all lower
- * case. If the user name passed in is not "postmaster", it is
- * returned unchanged.
- */
- char *
- postmaster(user)
- char *user;
- {
- static char *pm = "postmaster";
-
- if(strcmpic(user, pm) == 0) {
- return(pm);
- } else {
- return(user);
- }
- }
-
- /*
- * Return 1 iff the string is "UUCP" (ignore case).
- */
- isuucp(str)
- char *str;
- {
- if(strcmpic(str, "UUCP") == 0) {
- return(1);
- } else {
- return(0);
- }
- }
-
- /*
- ** sform(form) returns a pointer to a string that tells what 'form' means
- */
-
- char *
- sform(form)
- enum eform form;
- {
- if(form == ERROR) return("ERROR");
- if(form == LOCAL) return("LOCAL");
- if(form == DOMAIN) return("DOMAIN");
- if(form == UUCP) return("UUCP");
- if(form == ROUTE) return("ROUTE");
- return("UNKNOWN");
- }
-
- /*
- **
- ** getmynames(): what is my host name and host domain?
- **
- ** Hostname set by -h, failing that by #define HOSTNAME, failing
- ** that by gethostname() or uname().
- **
- ** Hostdomain set by -h, failing that by #define HOSTDOMAIN,
- ** failing that as hostname.MYDOM, or as just hostname.
- **
- ** See defs.h for the inside story.
- **
- */
-
- getmynames()
- {
- #ifdef HOSTNAME
- if (!*hostname)
- (void) strcpy(hostname, HOSTNAME);
- #endif
- #ifdef GETHOSTNAME
- if (!*hostname)
- gethostname(hostname, SMLBUF - 1);
- #endif
- #ifdef UNAME
- if (!*hostname) {
- struct utsname site;
-
- if (uname(&site) < 0)
- error(EX_SOFTWARE, "uname() call failed", 0);
- (void) strcpy(hostname, site.nodename);
- }
- #endif
- if (!*hostname)
- error(EX_SOFTWARE, "can't determine hostname.\n", 0);
- #ifdef HOSTDOMAIN
- if (!*hostdomain)
- (void) strcpy(hostdomain, HOSTDOMAIN);
- #endif
- #ifdef MYDOM
- if (!*hostdomain)
- (void) strcat(strcpy(hostdomain, hostname), MYDOM);
- #endif
- #ifdef AMIGA
- if (!*hostdomain)
- {
- (void) getdomainname(hostdomain, SMLBUF - 1);
- strins(hostdomain,hostname);
- }
- #endif
- if (!*hostdomain)
- (void) strcpy(hostdomain, hostname);
-
- (void) strcat(strcpy(hostuucp, hostname), ".UUCP");
- #ifdef AMIGA
- (void) getsmarthost(smarthost,SMLBUF - 1);
- #endif
-
-
- }
-
- /*
- * convert the Date: header to time_t value
- *
- * if any parsing error occured 0 is returned
- *
- */
- time_t
- get_time(char *ctime_string)
- {
- const char *mo[12] =
- {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
- };
- char mon[12];
- struct tm ret;
- register int i;
- time_t mail,today,diff;
-
- /*
- if(ctime_string[0]=='\0')
- return(0);
- /* e.g: Date: Sun, 28 Nov 1993 13:25: */
- sscanf (ctime_string, "%*s %*s %2d %s %d %2d:%2d:", &ret.tm_mday, mon, &ret.tm_year, &ret.tm_hour, &ret.tm_min);
- for (i = 0; i < 12; i++)
- if (!strncmp (mo[i], mon, 3))
- break;
- ret.tm_mon=i;
- ret.tm_year %= 1900;
- mail=mktime(&ret);
- today=time(&today);
- if(mail<1 || today<1)
- return(0);
- diff=difftime(today,mail);
- if(diff<86400) /* 24hours*60mins*60secs = 1 day in secs*/
- return(1);
- return(((diff/60)/60)/24);
- }
- @
-
-
- 2.3
- log
- @only in rmail mode the delivering time will be logged
- @
- text
- @d19 3
- d53 1
- a53 1
- static char *rcsid="$Id: misc.c,v 2.2 1993/11/28 16:01:05 Aussem Exp Aussem $";
- d239 2
- a240 1
- timezone=getenv("TZ");
- d253 1
- a253 1
- timezone?timezone:"GMT");
- @
-
-
- 2.2
- log
- @get_time() insert
- maillog() will now logs the duration of delivering the mail
- @
- text
- @d19 4
- d50 1
- a50 1
- static char *rcsid="$Id: misc.c,v 2.1 1993/11/23 19:58:39 Aussem Exp Aussem $";
- d116 17
- a132 6
- if(to_host[0]!='\0')
- fprintf(fp,"%s: %c '%s' '%s!%s' %ld bytes %d days\n",logtime,okay,from,to_host,to_user,size,get_time(dateline));
- else
- fprintf(fp,"%s: %c '%s' '%s' %ld bytes %d days\n",logtime,okay,from,to_user,size,get_time(dateline));
- fclose(fp);
- }
- @
-
-
- 2.1
- log
- @Version 2.0 check in
- @
- text
- @d19 3
- d46 1
- a46 1
- static char *rcsid="$Id: misc.c,v 1.7 1993/11/20 23:50:31 Aussem Exp Aussem $";
- d71 2
- a109 1
-
- d113 1
- a113 1
- fprintf(fp,"%s: %c '%s' '%s!%s' %ld bytes\n",logtime,okay,from,to_host,to_user,size);
- d115 1
- a115 1
- fprintf(fp,"%s: %c '%s' '%s' %ld bytes\n",logtime,okay,from,to_user,size);
- d137 1
- a137 1
- (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n",
- d399 1
- a399 1
- **
- d451 39
- @
-
-
- 1.7
- log
- @no ok, .. output if we are rmail
- @
- text
- @d19 3
- d43 1
- a43 1
- static char *rcsid="$Id: misc.c,v 1.6 1993/11/20 21:32:39 Aussem Exp Aussem $";
- @
-
-
- 1.6
- log
- @extended Debug options
- @
- text
- @d19 3
- d40 1
- a40 1
- static char *rcsid="$Id: misc.c,v 1.5 1993/11/06 15:59:47 Aussem Exp Aussem $";
- d74 1
- d90 1
- a90 1
- if(debug==NO)
- @
-
-
- 1.5
- log
- @maillog() now works better
- @
- text
- @d19 3
- d37 1
- a37 1
- static char *rcsid="$Id: misc.c,v 1.4 1993/10/18 23:50:32 Aussem Exp Aussem $";
- d47 1
- a47 1
- extern enum edebug debug; /* how verbose we are */
- a68 10
- # ifdef LOG
- void
- log(command, from, size)
- char *command, *from;
- long size;
- {
- writelog(" cmd: \"%s\" from %s",command,from);
- }
- # endif
-
- d85 11
- @
-
-
- 1.4
- log
- @enforcer hit in record() removed
- @
- text
- @d19 3
- d34 1
- a34 1
- static char *rcsid="$Id: misc.c,v 1.3 1993/09/18 16:47:47 Aussem Exp Aussem $";
- d77 2
- d80 2
- a81 2
- maillog(to, from, size,okay)
- char *to;
- a85 1
- extern char maillogfile[];
- d93 1
- a93 2
- if(!fp)
- fp=fopen(maillogfile,"a");
- d96 7
- a102 2
- fprintf(fp,"%s: %c '%s' '%s' %ld bytes\n",logtime,okay,from,to,size);
-
- @
-
-
- 1.3
- log
- @insert GNU license text in the header
- @
- text
- @d19 3
- d31 1
- a31 1
- static char *rcsid="$Id: misc.c,v 1.2 1993/09/10 01:51:50 Aussem Exp Aussem $";
- d112 4
- a115 4
- if (fd != NULL) {
- (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n",
- logtime, command, from, size);
- }
- @
-
-
- 1.2
- log
- @new support for wCNews styled logfile with maillog()
- @
- text
- @d2 1
- a2 1
- * Miscellaneous support functions for smail/rmail
- d4 14
- d19 3
- d28 1
- a28 1
- static char *rcsid="$Id: misc.c,v 1.1 1993/09/08 16:27:13 Aussem Exp Aussem $";
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d4 3
- a6 1
- * $Log$
- d8 1
- d11 1
- a11 1
- static char *rcsid="$Id$";
- a48 1
- #ifdef AMIGA
- d50 21
- a70 4
- #else
- FILE *fd;
- char *logtime, tbuf[50];
- int cmask;
- d72 2
- a73 3
- logtime = strcpy(tbuf, nows);
- logtime[16] = '\0';
- logtime += 4;
- a74 9
- cmask = umask(0);
- fd = fopen(logfile, "a");
- (void) umask(cmask);
- if (fd != NULL) {
- (void) fprintf(fd, "%s\t%ld\t%s\t%s\n",
- logtime, size, from, command);
- (void) fclose(fd);
- }
- #endif
- d88 1
- a88 1
- logtime[16] = 0;
- d93 1
- a93 1
- (void) fprintf(fd, "%s: %s, from %s, %ld bytes\n",
- @
-